package com.four.peoplemanage.holiday.dao;

import com.four.peoplemanage.holiday.entity.Holiday;
import com.four.peoplemanage.information.entity.Information;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HolidayDao {
    // 查看所有节假日
    @Select("<script>" +
            "SELECT * FROM traffic.holiday" +
            "<where>" +
            "    <if test=\"holiday_name != null\">" +
            " <bind holiday_name=\"Key\" value=\"'%'+holiday_name+'%'\"/>" +
            "        holiday_name like #{Key} " +
            "    </if>" +
            "    <if test=\"datetm != null\">" +
            "      and datetm = #{datetm}" +
            "     </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    List<Holiday> canHoliday(int start, int size,
                             String holiday_name, String datetm);
    //分页
    @Select("<script>" +
            "SELECT count(*) FROM traffic.holiday" +
            "<where>" +
            "    <if test=\"holiday_name != null\">" +
            " <bind holiday_name=\"Key\" value=\"'%'+holiday_name+'%'\"/>" +
            "        holiday_name like #{Key} " +
            "    </if>" +
            "    <if test=\"datetm != null\">" +
            "      and datetm = #{datetm}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countHoliday(String holiday_name, String datetm);

    //插入节假日
    @Insert("INSERT INTO traffic.holiday (holiday_name, datetm, sork_status, holiday_status) " +
            "VALUES (#{holiday_name}, #{datetm}, #{sork_status}, #{holiday_status})")
    int insertHoliday(Holiday holiday);

    //修改节假日
    @Update("<script>" +
            "  update holiday" +
            "        <set>" +
            "            <if test=\"null != holiday_name\"> " +
            "                holiday_name = #{holiday_name}," +
            "            </if>" +
            "            <if test=\"null != datetm\"> " +
            "                datetm = #{datetm}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int update(Holiday holiday);

    //删除节假日
    @Delete("DELETE FROM traffic.holiday where id=#{id}")
    public int delHolidayc(Integer id);

}
